﻿using Common.Core.Results;
using NetByDocker.Domain.Model.UserManage;

namespace NetByDocker.Web.Services
{
    /// <summary>
    /// 用户服务
    /// </summary>
    public class UserService
    {
        private readonly HttpClient _httpClient;
        private readonly ILogger<UserService> _logger;

        public UserService(HttpClient httpClient, ILogger<UserService> logger)
        {
            _httpClient = httpClient;
            _logger = logger;
        }

        public async Task<GetQueryPageResult<GetUserPageInfoResponse>> GetPageListAsync()
        {
            try
            {
                var result = await _httpClient.GetFromJsonAsync<ResultModel<GetQueryPageResult<GetUserPageInfoResponse>>>("/api/User/GetPageList?PageIndex=1&PageSize=10");
                if (result is not null && result.IsSuccess)
                    return result.Data;

                //var response = await _httpClient.GetAsync("/api/User/GetPageList?PageIndex=1&PageSize=10");
                //_logger.LogInformation($"Http status code: {response.StatusCode}");
                //if (response.IsSuccessStatusCode)
                //{
                //    var result = await response.Content
                //        .ReadFromJsonAsync(GetUserQueryPageInfoContext.Default.ResultModelGetQueryPageResultGetUserPageInfoResponse);
                //    return result?.Data;
                //}
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"获取用户列表报错 {ex.Message}");
            }

            return new GetQueryPageResult<GetUserPageInfoResponse>();
        }
    }
}